package com.atguigu.ggkt.vod.controller;


import com.atguigu.ggkt.model.vod.Video;
import com.atguigu.ggkt.result.Result;
import com.atguigu.ggkt.vod.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author lxx
 * @since 2022-06-30
 */
@RestController
@RequestMapping("/admin/vod/video")
@Api(tags = "小节管理接口")
public class VideoController {
    @Autowired
    private VideoService videoService;

    /**
     * 根据id获取小节
     * @param id 小节id
     * @return
     */
    @ApiOperation(value = "根据id获取小节")
    @GetMapping("video/{id}")
    public Result get(@PathVariable Long id) {
        Video video = videoService.getById(id);
        return Result.ok(video);
    }

    /**
     * 新增小节
     * @param video json格式的video对象
     * @return
     */
    @ApiOperation(value = "新增小节")
    @PostMapping("video")
    public Result save(@RequestBody Video video) {
        videoService.save(video);
        return Result.ok();
    }

    /**
     * 修改小节
     * @param video json格式的video对象
     * @return
     */
    @ApiOperation(value = "修改小节")
    @PutMapping("video")
    public Result updateById(@RequestBody Video video) {
        videoService.updateById(video);
        return Result.ok();
    }

    /**
     * 删除小节
     * @param id
     * @return
     */
    @ApiOperation(value = "删除小节")
    @DeleteMapping("video/{id}")
    public Result remove(@PathVariable Long id) {
        videoService.removeVideoAndVod(id);
        return Result.ok();
    }

}

